/*
 * PlaneTest.java: Plane class verificaton
 * 
 * 2008 Ron Gosa
 */

import java.util.Scanner;


public class PlaneTest {

    public static void main(String argv[]) {

        Scanner option = new Scanner(System.in);
        boolean firstClass;
        boolean economy;
        
        Plane myPlane = new Plane();
        
        while (true) {
            
            if (!myPlane.isPlaneFull()) {
                if (myPlane.isFirstClassAvailable()) {
                    System.out.println("Enter '1' for first class.");
                }
                if (myPlane.isEconomyAvailable()) {
                    System.out.println("Enter '2' for economy.");
                }
            }
            System.out.println("Enter '3' to verify a reservation");
            System.out.println("Enter '4' to complete reservation.");
            System.out.println();
            System.out.print(">");

            int selection = option.nextInt();

            // reserve first class
            if (selection == 1) {
                // first class is full
                if(!myPlane.addFirstClassReservation()) 
                {
                    if (myPlane.isEconomyAvailable()) {
                        System.out.println("First Class is full. Choose economy");
                        System.out.print("1. Yes, 2. No. Your choice: ");
                        
                        selection = option.nextInt();
                        
                        if (selection == 1) {
                            myPlane.addEconomyReservation();
                            System.out.printf("Economy Class. Seat #%d\n",
                                    myPlane.getLastSeatReserved());
                        }
                        
                        else if(selection == 2) {
                            System.out.println("\nNext flight leaves in 3 hours.");
                        }
                    } else {
                        System.out.println("\nPlane is full, Next flight leaves in 3 hours.");   
                    }

                }
                else
                    System.out.printf("First class. Seat #%d\n\n", 
                                myPlane.getLastSeatReserved());
            }
            
            // reserve economy
            else if (selection == 2) {

                // economy class is full
                if(!myPlane.addEconomyReservation()) {
                    if (myPlane.isFirstClassAvailable()) {
                        System.out.println("Economy is full. Choose First class?");
                        System.out.print("1. Yes, 2. No. Your choice: " );
                        
                        selection = option.nextInt();
    
                        if (selection == 1) {
                            myPlane.addFirstClassReservation();
                            System.out.printf( "First Class. Seat #%d\n",
                                    myPlane.getLastSeatReserved());
                        }
                        
                        else if(selection == 2) {
                            System.out.println( "\nNext flight leaves in 3 hours.");
                        }
                    } else {
                        System.out.println("\nPlane is full, Next flight leaves in 3 hours.");   
                    }                      
                    
                }
                else
                    System.out.printf("\nEconomy class. Seat #%d\n\n",
                            myPlane.getLastSeatReserved());
            }

            // verify reservation
            else if(selection == 3) {
                
                System.out.println("Enter seat number: ");
                selection = option.nextInt();
                
                if(myPlane.checkReservation(selection))
                    System.out.printf("\nSeat %1$d is reserved.\n\n", selection);
                else
                    System.out.printf("\nSeat %1$d is available.\n\n", selection);
            }            
            
            // complete reservation
            else if (selection == 4) {
                System.out.println("Reservation complete.");
                break;
            }
        }

        System.out.println();
        myPlane.printSummary();
    }
}


